import { Button, Result } from "@/components/base";
import { runtime } from 'dingtalk-jsapi';
import { Controller } from '@/controller';
import { CORP_ID_MAP } from "@/constants/corpIdMap";
import React from "react";

function OpenInBrowser() {

    const [code, setCode] = React.useState<string | null>(null);

    return (
        <Result
            title="浏览器中调试应用"
            subTitle={`http://127.0.0.1/login-browser?code=${code}&c=${Controller.instance.company}`}
            extra={
                <Button
                    type="primary"
                    key="console"
                    onClick={() => {
                        if (!Controller.instance.company) return;
                        runtime.permission.requestAuthCode({ corpId: CORP_ID_MAP[Controller.instance.company] })
                            .then(({ code }) => {
                                setCode(code);
                            })
                    }}
                >
                    刷新链接
                </Button>
            }
        />
    )
}
export default OpenInBrowser;